#ifndef MovingChargeTcpServer_H
#define MovingChargeTcpServer_H
#include <thread>
#include <mutex>
#include <condition_variable>
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
#include "logger.h"
#include "utils.h"
#include "localTcpServer.h"

class MovingChargeTcpServer : public QObject
{
    Q_OBJECT
public:
    MovingChargeTcpServer();
    ~MovingChargeTcpServer();
    bool init();

Q_SIGNALS:
    void sigMoveServo(int);

public slots:
    void slotReplyClient(std::string num, std::string reslut);

private:
    bool mInited = false;
    LocalTcpServer m_server;

    int localPort = 49999;
    std::string localIP = "192.168.0.122";
    void parseDitInfo(const char *data, int size);

    /*工作线程*/
    std::string mJsonstr;
    bool mWorkerRunnig = false;
    std::condition_variable mWorkercond;
    bool mWorkerRecvStatus;
    std::mutex mWorkerProcMutex;

    std::mutex mResMutex;
    std::thread worker;
    void workThreadFun();

    void loadINI();
    void print_base_info();
};

#endif // MovingChargeTcpServer_H
